package com.lss.cloud.Exception;

import com.lss.cloud.Resp.ResultData;
import com.lss.cloud.Resp.ReturnCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 2024/3/14-12:21
 * 功能:
 */
@Slf4j
@RestControllerAdvice
// = @ControllerAdvice
//  + @ResponseBody
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResultData exception(Exception e){
        log.info("全局异常处理：{}",e.getMessage());
        System.out.println(e);

        return ResultData.failed(ReturnCodeEnum.RC500.getCode(), e.getMessage());
    }
}
